package com.zany.util.xml;

import java.util.Map;
import java.util.HashMap;
import java.util.List;

import org.jdom.Document;
import org.jdom.Element;

import com.zany.util.ZanyException;
import com.zany.util.cache.SCache;

public class SystemXML implements XMLWrapper {
	
	private SCache sCache;
	public SystemXML() {}

    public void fill(Document xmlDoc) throws ZanyException {
        Element root = xmlDoc.getRootElement(); // 文档的根节点
        Element  eMxUnit = null, childEme = null;
        Map tmpMap = null;
        List tmpList = root.getChildren();
        if (root==null) return;
        sCache= new SCache();
        if ((tmpList != null) && (!tmpList.isEmpty())) {
        	for (int i = 0; i < tmpList.size(); i++) {
        		tmpMap = new HashMap();
        		eMxUnit = (Element) tmpList.get(i);
        		String parent=eMxUnit.getName();
        		List child = eMxUnit.getChildren();
        		if ((child != null) && (!child.isEmpty())) {
        			for (int j = 0; j < child.size(); j++) {
        				childEme = (Element) child.get(j);
        				String name = childEme.getName();
        				String value = childEme.getText();
        				tmpMap.put(name, value);
                    }
        		}
        		sCache.setChildMap(parent,tmpMap);
        	}
        }
    }
    public  SCache getSCache(){
        return sCache;
   }
}
